package com.xyz.study.design_mode.j_strategy.mode;

/**
 * role: Context 上下文
 * @author XYZ
 * @version 1.0.0
 * @since 2021/1/15
 */
public enum PrinterEnum {
    LINUX("linux", new PrinterLinux()),
    WINDOWS("windows", new PrinterWindows());
    private final String code;
    private final Printer printer;
    PrinterEnum(String code, Printer printer) {
        this.code = code;
        this.printer = printer;
    }

    /**
     * 获取策略
     * @param code code
     * @return {@link Printer}
     */
    public static Printer getPrinter(String code){
        for (PrinterEnum item: values()) {
            if (item.code.equals(code)) {
                return item.printer;
            }
        }
        return null;
    }
}
